package com.kkb.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class DruidUtils {
     public static DataSource dataSource = null;

     static {
         try {
             InputStream resourceAsStream = DruidUtils.class.getClassLoader().getResourceAsStream("druid.properties");
             Properties properties = new Properties();
             properties.load(resourceAsStream);

             dataSource = DruidDataSourceFactory.createDataSource(properties);
         } catch (IOException e) {
             e.printStackTrace();
         } catch (Exception e) {
             e.printStackTrace();
         }
     }

     public static DataSource getDataSource(){
         return dataSource;
     }

     public static Connection getConnection() throws SQLException {
         Connection connection = dataSource.getConnection();
         return connection;
     }
}
